#include <iostream>

using std::cout;
using std::endl;

template <class T>
class RAII
{
public:
    RAII(T * p)
    : _p(p)
    {   cout << "RAII(T*)" << endl; }

    ~RAII()
    {
        cout << "~RAII()" << endl;
        if(_p) {
            delete _p;
            _p = nullptr;
        }
    }

    T * operator->()
    {   return _p;  }

    T & operator*()
    {   return *_p;    }

    RAII(const RAII & ) = delete;
    RAII & operator=(const RAII &) = delete;

private:
    T * _p;//_p指向的是堆空间的资源
};

class Point
{
public:
    Point(int ix, int iy)
    : _ix(ix)
    , _iy(iy)
    {   cout << "Point(int,int)" << endl;   }

    ~Point()
    {   cout << "~Point()" << endl; }

    void print() const
    {   
        cout << "(" << _ix
             << "," << _iy
             << ")" << endl;
    }

private:
    int _ix;
    int _iy;
};

int main()
{
    RAII<Point> raii(new Point(1, 2));
    raii->print();
    //(raii.operator->())->print();

    return 0;
}

